//
//  RegKnownViewController.m
//  YuanCheng
//
//  Created by 朱亚杰 on 16/4/6.
//  Copyright © 2016年 dongshangtong. All rights reserved.
//

#import "RegKnownViewController.h"

@interface RegKnownViewController ()
{
    CGFloat _maxScrollHeight;
}
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIView *titleView;

@end

@implementation RegKnownViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI {
    
    _titleView.backgroundColor = GreenColor;
    _scrollView.backgroundColor = BackgroundColor;
    
    //    1.注册须知
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 45)];
    label.backgroundColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"注册须知";
    label.font = SubTitleFont;
    [_scrollView addSubview:label];
    _maxScrollHeight = CGRectGetMaxY(label.frame);
    
    //    2.每一条的内容
    NSArray *arr = @[
                     @"1.背景优势：\n  全国心脑远程联盟是一个为医生提供协作发展的平台。以医生集团为核心，开展“线上复诊”、“慢病管理”为主旨的家庭医生特色服务。为医生提供最新学术前沿资讯，跨地域学术交流的同时，严密保护医生隐私。\n  全国心脑远程联盟致力于为医患之间提供“远程阅片、电子处方、坐诊手术、家庭医生”等多种服务模式，使医生多点执业、分级诊疗成为现实，为心脑血管患者提供高效、优质、便捷的互联网医疗服务",
                     @"2.会员享有：\n  A.联盟头条：掌握集团实时新闻 了解最新医疗政策;\n  B.名医风采：收集专科名医事迹 展示医疗学术成果;\n  C.医学专题：汇集国内医学现状 网络业内医学巨献; \n  D.病例展示：收集优质病例资源 丰富专科诊疗经验;\n  E.活动会议：掌握线下学术交流 把握行业最新动态;\n  F.千县万医：直击专家学术课程 提升自我医学经验;\n  G.医生工作站：记录在线工作明细 浏览订单处方详情;\n  H.推荐二维码：推荐好友即得积分 机制健全奖励丰厚;\n  I.分享医生圈：业内专家分享交流 得百家智慧之精华;\n  J.积分排行榜：当前排名实时查看 积分凭证获取收益",
                     @"3.注册条件：\n  A.所属机构：申请的医疗机构必须是国内具有正规资质的二甲级及以上公立医院的心脑血管相关科室医生或医务工作者.\n  B.执业资质：拥有国家认证的医生执业资格证;",
                     @"4.注册流程：\n  A.申请人关注“全国心脑远程联盟”公众号，并点击会员申请，绑定手机号;\n   B.申请人填写《全国心脑远程联盟——注册申请表》，填写完毕，提交，等待审核;\n  C.工作人员与医生打电话核实信息，确认信息无误后，审核通过；\n  D.系统提示审核通过，并颁发会员证书;\n  E.完成会员注册。"
                     ];
    [self addItemsWithArray:arr];
    
    _scrollView.contentSize = CGSizeMake(0, _maxScrollHeight + 20);
}

- (void)addItemsWithArray:(NSArray *)array {
    
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        //        1. 父类view
        NSString *contentStr = obj;
        CGFloat labelHeight = [YCCommonTool heightWithStr:contentStr lineSpacing:8 fontSize:14 maxLabelWidth:MaxViewWidth];
        NSInteger index = (NSInteger)idx;
        CGFloat viewHeight = labelHeight + 31;
        if (index == (array.count - 1)) {
            viewHeight = labelHeight + 15;
        }
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, _maxScrollHeight, SCREEN_WIDTH, viewHeight)];
        view.backgroundColor = [UIColor whiteColor];
        [_scrollView addSubview:view];
        _maxScrollHeight = CGRectGetMaxY(view.frame);
        
        //        2. 内容
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(MarginWidth, 0, MaxViewWidth, labelHeight)];
        label.font = LevelFont;
        label.numberOfLines = 0;
        label.textColor = Gray;
        
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        //    设置左右对齐
        style.firstLineHeadIndent = 1;
        style.alignment = NSTextAlignmentJustified;
        //    行间距
        style.lineSpacing = 8;
        [attributedStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, contentStr.length)];
        label.attributedText = attributedStr;
        [view addSubview:label];
        
        //        3. 分割线(最后一行不添加分割线)
        if (index != (array.count - 1)) {
            
            CGFloat dividerY = CGRectGetMaxY(label.frame) + 15;
            UIView *divider = [[UIView alloc] initWithFrame:CGRectMake(0, dividerY, SCREEN_WIDTH, 1)];
            divider.backgroundColor = DividerColor;
            [view addSubview:divider];
        }
    }];
}

#pragma mark - 返回上级页面
- (IBAction)backAction {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
